package com.zsc.wxm.ysh.anjo.house.controller;

import com.zsc.wxm.ysh.anjo.house.service.PromiseService;
import com.zsc.wxm.ysh.anjo.result.PageResult;
import com.zsc.wxm.ysh.anjo.result.Result;
import com.zsc.wxm.ysh.anjo.service.base.model.resources.dto.PromiseDTO;
import com.zsc.wxm.ysh.anjo.service.base.model.resources.qo.PromiseQuery;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * 描述：
 *
 * @author playmaker
 * @since 2021/3/9 23:37
 */
@RestController
@RequestMapping("/house/promise")
public class PromiseController {

    @Resource
    private PromiseService service;

    @PostMapping("/add")
    @ApiOperation("新增合约")
    public Result add(@RequestBody PromiseDTO param) {
        service.add(param);
        return Result.ok("新增成功");
    }

    @PostMapping("/list-page")
    @ApiOperation("分页查询")
    public PageResult listPage(@RequestBody PromiseQuery query) {
        return service.listPage(query);
    }

    @PutMapping("/update")
    @ApiOperation("更新")
    public Result updatePromise(@RequestParam Long id, @RequestParam(required = false) Integer status,
                                @RequestParam(required = false) LocalDateTime endTime,
                                @RequestParam(required = false) Long houseId, Long rentUserId) {
        service.updatePromise(id, status, endTime, houseId, rentUserId);
        return Result.ok("更新成功");
    }
}
